package com.haisen.lee.serviceimpl;

import java.net.URL;
import java.util.Set;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.haisen.lee.domain.FormDictionary;
import com.haisen.lee.service.IDomParser;

public class FormDomParserImpl implements IDomParser {

	private static Set<String> attributeNeedParser;
	private URL searchWebSite;
	private FormDictionary formDictionary;
	private double formWeight;
	private URL actionUrl;

	static {
		attributeNeedParser.add("ID");
		attributeNeedParser.add("ACTION");
	}

	@Override
	public void contentExtractor(Node formNode) {
		NamedNodeMap attributeNodes = formNode.getAttributes();
		for (String attributeName : attributeNeedParser) {
			Node attributeNode = attributeNodes.getNamedItem(attributeName);
			if (attributeNode != null) {

			}
		}

		NodeList childrenNodes = formNode.getChildNodes();
		for (int i = 0; i < childrenNodes.getLength(); i++) {
			contentExtractorChildrenNode(childrenNodes.item(i));
		}
	}

	public void contentExtractorChildrenNode(Node node) {
		Element elmt = (Element) node;
		// check if contain need parser
		if (elmt.getTagName().equals("INPUT")) {

		}
	}

	@Override
	public void init() {

	}

	@Override
	public void setUrl(URL url) {
		this.searchWebSite = url;

	}

	@Override
	public void setFormDictionary(FormDictionary formDictionary) {
		this.formDictionary = formDictionary;
	}

	public double getFormWeight() {
		return formWeight;
	}

	public URL getActionUrl() {
		return actionUrl;
	}

}
